package com.heima.common.exception;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
@Configuration
public class ExceptionCatch {
    //不可预知异常
    @ExceptionHandler(Exception.class)
    public ResponseResult exception(Exception ex){
        log.error("Exception ex:{}",ex);
        return ResponseResult.errorResult(AppHttpCodeEnum.SERVER_ERROR,"您网络有问题哦");
    }


    //可预知异常
    @ExceptionHandler(CustomException.class)
    public ResponseResult custException(CustomException cust){
        log.error("CustomException cust:{}",cust);

        return ResponseResult.errorResult(cust.getAppHttpCodeEnum());
    }
}
